#ifndef SEQUENCEITEM_H
#define SEQUENCEITEM_H

#include <QObject>
#include <QString>

/**
 * @class SequenceItem
 * The SequenceItem class describes a single event that can be fired
 * within a sequence. So far, the event can be the playback of a new
 * track or a light change.
 * An item also has a "delay time", (in milliseconds), that is the time
 * to wait after the begin of triggered event, to trigger a new event.
 * If this value is ::DELAY_INFINITE, next event is not triggered automatically.
 * This class also holds an optional index that is where a sequence of items
 * should jump after the current one.
 *
 */

class SequenceItem : public QObject
{
   Q_OBJECT
public:
   /** type of event to triger */
   typedef enum
   {
      TRACK,
      LIGHT,
      INVALID_EVENT
   } eventType;

   /** set this to ::m_delayMs to avoid automatic trigger of next event */
   static const int DELAY_INFINITE = -1;

   /** set this to ::m_indexOfNext to state that this item does not define the next */
   static const int NEXT_IS_UNDEFINED = -1;

public:
   explicit SequenceItem( int delayMs = 0,
                          const QString & label = QString(),
                          SequenceItem::eventType typeOfEvent = SequenceItem::INVALID_EVENT,
                          int indexOfNext = NEXT_IS_UNDEFINED,
                          QObject *parent = 0);

   int delayMs() const {
      return m_delayMs;
   }

   QString label() const {
      return m_label;
   }

   SequenceItem::eventType type() const {
      return m_type;
   }

   int indexOfNext() const {
      return m_indexOfNext;
   }

   void setDelayMs( int delayMs) {
      m_delayMs = delayMs;
   }

   void setLabel(const QString &label) {
      m_label = label;
   }

   void setType(SequenceItem::eventType type) {
      m_type = type;
   }

   void setIndexOfNext( int nextIndex) {
      m_indexOfNext = nextIndex;
   }

   QString serialize() const;

private:
   int m_delayMs;       /**< time (ms) between the launch of previous item and this item */
   QString m_label;     /**< a string that identifies an event of a given type */
   /** index of the sequence item that will be activated after this one.
     * If value is -1, sequence engine will decide next (usually following item). */
   int m_indexOfNext;
   SequenceItem::eventType m_type;  /**< type of event */
};

Q_DECLARE_METATYPE(const SequenceItem *)

bool operator ==(const SequenceItem &left, const SequenceItem &right);

#endif // SEQUENCEITEM_H
